document.addEventListener("deviceready",onDeviceReady, false);
document.addEventListener("jpush.openNotification", onOpenNotification, false);
function onDeviceReady() {
        document.addEventListener("jpush.receiveRegistrationId", function (event) {
              //alert("receiveRegistrationId" + JSON.stringify(event));
          }, false)
        initiateUI();
      };

function onOpenNotification(){
  try {
         var alertContent;
         if (device.platform == "Android") {
           alertContent = event.alert;
         } else {
           alertContent = event.aps.alert;
         }
         //alert("open Notification:" + alertContent);
         //this.$f7.router.navigate('/events/')
       } catch (exception) {
         console.log("JPushPlugin:onOpenNotification" + exception);
       }
}

function initiateUI() {
  if ('JPush' in window) {
     console.log('initialize JPush...');
     try {
         window.JPush.init();
         window.JPush.setDebugMode(false);
         if (device.platform != "Android") {
             window.JPush.setApplicationIconBadgeNumber(0);
         }
     } catch (exception) {
         console.log(exception);
     }
 } else {
     console.error('JPush is not exist...');
 }
}
